package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {//有一个类

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);
    //插入语句 sql 语句的配置文件
@AutoFill(value= OperationType.INSERT)
    void insert(Dish dish);

    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);
//@Select("select *from dish where id={#id}")
    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);//根据id查询菜品
//@Delete("delete from dish where id = #{id}")
    @Delete("delete form dish where id=#{id}")
    void deleteById(Long id);
//但是我们传递过来的数据就是属性的化不全，公共字段的话需要我们自动填充，所以需要一个注解
    @AutoFill(value= OperationType.UPDATE)
    void update(Dish dish);

    List<Dish> list(Dish dish);
//@Select("select * from dish where category_id = #{categoryId}")
//    List<Dish>  selectByCategoryId(Long categoryId);



    /*
    * @Insert into dish (name,description,status,price,create_time,update_time,create_user,
    * update_user,category_id,serving_size) values()
    *
    *
    * */
}
